#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
using namespace std;

void PrintPending(const sigset_t& pending)
{
    for(int signo = 31; signo > 0; signo--)
    {
        if(sigismember(&pending, signo))
        {
            cout << "1";
        }      
        else
        {
            cout << "0";
        }
    }
    cout << endl;
}

void handler(int signo)
{    
    sigset_t pending;
    cout << "############################" << endl;
    sigpending(&pending);
    PrintPending(pending);     
    cout << "############################" << endl;
    cout << "handler " << signo << endl;
} 

int main()
{
    signal(2, handler);
    while(true)
    {
        sleep(1);
    }
    return 0;
}
